package midleWare

import (
	"github.com/gin-gonic/gin"
)

func MiddleWare() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*") // 这是允许访问所有域

		c.Header("Access-Control-Allow-Credentials", "true") // 跨域请求是否需要带cookie信息 默认设置为true
		//  header的类型
		c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域
		c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, custom-header, Cache-Control,XMLHttpRequest, X-Requested-With")

		c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE")
		if c.Request.Method == "OPTIONS" {
			c.JSON(200, "Options Request!")
		}
		c.Next()
	}
}
